package org.pzy.repository;

import org.pzy.entity.User;
import org.pzy.entity.UserVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: DRevelation
 * @Date: 2022/8/30 14:13
 */
@Repository
public interface UserRepository2 extends PagingAndSortingRepository<User, Long> {

    @Query(value = "select * from user where password = :password", nativeQuery = true)
    Page<User> findUserByPassword(@Param("password") String password, Pageable pageable);

    // https://blog.csdn.net/weixin_44449518/article/details/127266867?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-4-127266867-blog-103412827.235%5Ev38%5Epc_relevant_default_base3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ERate-4-127266867-blog-103412827.235%5Ev38%5Epc_relevant_default_base3&utm_relevant_index=5
    @Query("select t1.id as userId, t1.username as username, t2.deptName as deptName from User t1 join Dept t2 on t1.deptId=t2.id where t2.deptName like %:deptName%")
    Page<List<Map<String, Object>>> findUserByDeptName(@Param("deptName") String deptName, Pageable pageable);
}
